<?php
// 本类由系统自动生成，仅供测试用途
namespace app\index\Controller;
use think\facade\Session;
use workflow\workflow;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;


class Index {
	use \liliuwei\think\Jump; 
	
    public function index(){
	 View::assign('user',Db::name('user')->field('id,username,role')->select());
     return View::fetch();
    }
	public function welcome(){
	   View::assign('user',Db::name('user')->field('id,username,role')->select());
      return  View::fetch();
    }
	public function doc(){
      return  View::fetch();
    }
	public function login(){
		Session::clear();
		$info = Db::name('user')->find(input('id'));
        Session::set('uid', $info['id']);
		Session::set('uname', $info['username']);
		Session::set('role', $info['role']);
		return $this->success('登录成功');
	}
	public function upload()
    {
		if (Request::isPost()) {
			$files = Request::file('file');
			foreach ($files as $file) {
				$info = \think\facade\Filesystem::disk('public')->putFile( 'uploads', $file);
				if ($info) {
					$data[] = $info;
				} else {
					$error[] = $info;
				}
			}
			return json(["code" =>0, "msg" => $data, "data" => $info]);
		}
	$id = input('id');
	$url = 'upload';
	return <<<php
	<div class="page-container">
    <input type="hidden" id="callbackId" value="{$id}">
    <div><div id="drag">
                    <label for="file-input">
                        <img  width="110px"src="">
                    </label>
                </div>
                <input type="file" accept="*/*" name="file[]" id="file-input" multiple class="input-file" style="display: none">
     </div>
</div>
<script type="text/javascript" src="/static/work/jquery-1.7.2.min.js" ></script>
<script type="text/javascript" src="/static/work/lib/layer/2.4/layer.js" ></script>
<script type="text/javascript" src="/static/work/workflow.5.0.js" ></script>
<script type="text/javascript" src="/static/lib/H5upload.js" ></script>
<script>
    $(function () {
        var callbackId = $("#callbackId").val();
        $("#file-input").tpUpload({
            url: '{$url}',
            data: {a: 'a'},
            drag: '',
            start: function () {
                layer_msg = layer.msg('正在上传中…', {time: 100000000});
            },
            progress: function (loaded, total, file) {
                $('.layui-layer-msg .layui-layer-content').html('已上传' + (loaded / total * 100).toFixed(2) + '%');
            },
            success: function (ret) {
                callback(callbackId,ret.msg[0],ret.data);
            },
            error: function (ret) {
                layer.alert(ret);
            },
            end: function () {
                layer.close(layer_msg);
            }
        });

    });
    /**
     * 数据回调
     * @param id
     * @param value
     */
    function callback(id,value,name) {
        if (window.parent.frames.length == 0){
            layer.alert('请在弹层中打开此页');
        } else {
            parent.document.getElementById(id).value = value;
			parent.$("#s"+id).remove();
			var data = '<br/><b id="s'+id+'">'+name+'</b>';
			parent.$('#b'+id).after(data);
			parent.$('#b'+id).html('上传成功！');
			parent.$('#b'+id).removeAttr('onclick');
            Tpflow.lclose();
        }
    }
</script>
php;
    }
	
	
}